package com.leoman.plz_p.views.mine;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ListView;

import com.leoman.plz_p.R;
import com.leoman.plz_p.adapter.MissionDetailAdapter;
import com.leoman.plz_p.constants.Constants;
import com.leoman.plz_p.interfaces.MissionDetailView;
import com.leoman.plz_p.module.bean.MissionDetailBean;
import com.leoman.plz_p.presenter.MissionDetailPresenter;
import com.leoman.plz_p.views.homepage.PointDetailActivity;
import com.leoman.plz_p.weidget.NavBar;

import java.util.List;

import butterknife.Bind;
import cn.com.corelib.base.BaseActivity;

public class MissionDetailActivity extends BaseActivity<MissionDetailView, MissionDetailPresenter> implements MissionDetailView {

    private String missionTitle;
    private String missionId;

    public static Intent getLaunchIntent(Context context,String missionTitle,String id) {
        Intent intent = new Intent(context, MissionDetailActivity.class);
        intent.putExtra(Constants.KEY_MISSION_TITLE,missionTitle);
        intent.putExtra(Constants.KEY_MISSION_ID,id);
        return intent;
    }

    @Bind(R.id.nav)
    NavBar nav;
    @Bind(R.id.ls_mission)
    ListView lsMission;

    private MissionDetailAdapter adapter;

    @Override
    protected int getLayoutId() {
        return R.layout.ac_mission_detail;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        missionTitle=getIntent().getStringExtra(Constants.KEY_MISSION_TITLE);
        missionId=getIntent().getStringExtra(Constants.KEY_MISSION_ID);
        getPresenter().getMissionList(missionId);
        nav.setTitle(missionTitle);
        adapter=new MissionDetailAdapter(getViewContext());
        lsMission.setAdapter(adapter);
        adapter.setOnItemClick(new MissionDetailAdapter.onItemClick() {
            @Override
            public void onVideoClick(int grandpaPosition, int parentPosition, int position) {

            }

            @Override
            public void onTestClick(int grandpaPosition, int parentPosition, int position) {
                startActivity(PointDetailActivity.getLaunchIntent(getViewContext(),adapter.getItem(grandpaPosition).getId()+""));
            }
        });
    }

    @Override
    protected MissionDetailPresenter createPresenter() {
        return new MissionDetailPresenter();
    }


    @Override
    public void obtainMissionDetail(List<MissionDetailBean> taskList) {
        adapter.replaceAll(taskList);
    }
}